﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core;
using Frogism.Domain;
using NUnit.Framework;

namespace Frogism.Tests
{
    [TestFixture]

    public class ChartDataTests
    {
        [Test]
        public void YearList()
        {
            var bookList = new List<IBook>();
            var b = new Book();
            b.Id = 1;
            b.Reads.Add(new Read() { Id=1, BookId = 1, Page = 10, ReadDate = new DateTime(2008, 12, 1) });
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 10, ReadDate = new DateTime(2009, 3, 4) });
            bookList.Add(b);

            var b2 = new Book();
            b2.Id = 2;
            b2.Reads.Add(new Read() { Id = 3, BookId = 2, Page = 10, ReadDate = new DateTime(2007, 12, 1) });
            b2.Reads.Add(new Read() { Id = 4, BookId = 2, Page = 10, ReadDate = new DateTime(2009, 3, 4) });
            bookList.Add(b2);
            var mgr = new Frogism.Core.ReportPerYear(bookList);
            var lst = mgr.GetYearList();
            Assert.AreEqual(3, lst.Count());
            Assert.AreEqual(2007, lst[0]);
            Assert.AreEqual(2008, lst[1]);
            Assert.AreEqual(2009, lst[2]);

        }
        [Test]
        public void PagesPerYear()
        {
            var bookList = new List<IBook>();
            var b = new Book();
            b.Id = 1;
            b.IsFinished = true;
            b.GoalYear = 2009;
            b.Reads.Add(new Read() { Id = 1, BookId = 1, Page = 11, ReadDate = new DateTime(2008, 12, 1) });
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 20, ReadDate = new DateTime(2009, 3, 4) });
            bookList.Add(b);

            var b2 = new Book();
            b2.Id = 2;
            b2.IsFinished = false;
            b2.GoalYear = 2009;
            b2.Reads.Add(new Read() { Id = 3, BookId = 2, Page = 10, ReadDate = new DateTime(2007, 12, 1) });
            b2.Reads.Add(new Read() { Id = 4, BookId = 2, Page = 33, ReadDate = new DateTime(2009, 3, 4) });
            bookList.Add(b2);
            var mgr = new Frogism.Core.ReportPerYear(bookList);
            var lst = mgr.GetStats();
            Assert.AreEqual(3,lst.Count());
            Assert.AreEqual(2007, lst.ElementAt(0).Year);
            Assert.AreEqual(10, lst.ElementAt(0).PagesRead);
            Assert.AreEqual(0, lst.ElementAt(0).BooksFinished);

            Assert.AreEqual(2008, lst.ElementAt(1).Year);
            Assert.AreEqual(11, lst.ElementAt(1).PagesRead);
            Assert.AreEqual(0, lst.ElementAt(1).BooksFinished);


            Assert.AreEqual(2009, lst.ElementAt(2).Year);
            Assert.AreEqual(32, lst.ElementAt(2).PagesRead);
            Assert.AreEqual(1, lst.ElementAt(2).BooksFinished);

        }


        [Test]
        public void MonthList()
        {
            var bookList = new List<IBook>();
            var b = new Book();
            b.Id = 1;
            b.Reads.Add(new Read() { Id = 1, BookId = 1, Page = 10, ReadDate = new DateTime(2008, 12,31) });
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 15, ReadDate = new DateTime(2009, 1, 1) });
          
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 17, ReadDate = new DateTime(2009, 1, 5) });
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 33, ReadDate = new DateTime(2009, 1, 31) });
            b.Reads.Add(new Read() { Id = 2, BookId = 1, Page = 35, ReadDate = new DateTime(2009, 2, 1) });

            bookList.Add(b);

            var mgr = new Frogism.Core.ReportPerMonth(bookList);
            var list = mgr.GetStats(2009);
            Assert.AreEqual(1, list.ElementAt(0).Year);
            Assert.AreEqual(23, list.ElementAt(0).PagesRead);


        }
    }
}
